﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Routing;

namespace Huasky.MyWrod.Core.Annotations;


/// <summary>
/// 可以实现routeattribute和apicontroller的功能，增加了默认模板。
/// 并且增加了swagger分组支持
/// 默认不允许匿名访问
/// </summary>
/// 主要起到增强的功能，也可以使用系统的ApiController，非强制要求使用
public class HuaskyAPIAttribute(string template = "[controller]", string groupName = "Default")
    : ApiControllerAttribute,
    IAuthorizeData,
    IRouteTemplateProvider,
    IApiDescriptionGroupNameProvider
{


    #region IRouteTemplateProvider

    public string Name { get; set; }

    public int? Order { get; set; }

    public string Template { get; } = template;

    #endregion

    #region IApiDescriptionGroupNameProvider

    //给swagger使用的

    public string GroupName { get; } = groupName;

    #endregion

    public override string ToString()
    {
        return GroupName;
    }

    #region IAuthorizeData

    /// <summary>
    /// 授权策略
    /// </summary>
    public string Policy { get; set; }
    /// <summary>
    /// 授权角色
    /// </summary>
    public string Roles { get; set; }
    public string AuthenticationSchemes { get; set; }

    #endregion

}
